package com.kyhd.audio.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.kyhd.audio.dao.model.Novel;

@Repository
public interface NovelRepository extends JpaRepository<Novel, Long>,JpaSpecificationExecutor<Novel> {

	@Transactional
	@Query(value="select t.* from wm_novel_content t group by t.content_novel_id order by t.content_novel_id desc limit ?1",nativeQuery=true )
	List<Novel> getNovelIdsByNum(int num);
	
	@Transactional
	@Query(value="select t.content_id from wm_novel_content t where t.content_novel_id=?1 and t.audio=0",nativeQuery=true )
	List<String> getByNovelId(String novelId);

	@Transactional
	@Query(value="select t.* from wm_novel_content t where t.content_id=?1",nativeQuery=true )
	Novel getByContentId(String contentId);
	
	@Transactional
	@Query(value="select t.* from wm_novel_content t where t.content_novel_id=?1 and t.content_id=?2",nativeQuery=true )
	Novel getByNovelIdAndContentId(String novelId, String contentId);
}